package org.gd.hellojson.jackson;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class JacksonReadExample {

    public static void main(String[] args) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            // read from file, convert it to user class
            //JacksonUser user = mapper.readValue(new File("user.json"), JacksonUser.class);
            // display to console
            //System.out.println(user);

            String json =
                    "{\n" +
                    "    \"key1\": \"value1\",\n" +
                    "    \"key2\": \"value2\"\n" +
                    "}";

            Map<String,String> map = mapper.readValue(json,
                    new TypeReference<HashMap<String,String>>(){});

            System.out.println(map.get("key1"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
